import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class GetSessionId {
    public static void main(String[] args) throws Exception {
        String url = "http://oa.zdsoft.cn/resource/js/session.jsp?_=" + System.currentTimeMillis() + "&s_ajax=false";
        
        // 1. 发起 HTTP GET 请求
        HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
        connection.setRequestMethod("GET");
        
        // 2. 读取返回的 JS 代码
        BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        StringBuilder response = new StringBuilder();
        String line;
        while ((line = reader.readLine()) != null) {
            response.append(line);
        }
        reader.close();
        
        // 3. 使用正则提取 SessionId
        String jsCode = response.toString();
        Pattern pattern = Pattern.compile("return \"([A-Z0-9]+)\"");
        Matcher matcher = pattern.matcher(jsCode);
        
        if (matcher.find()) {
            String sessionId = matcher.group(1);
            System.out.println("SessionId: " + sessionId);  // 输出：9D96B8A08151015223025A12B4C9D870
        } else {
            System.out.println("SessionId not found!");
        }
    }
}